package com.baizhi;

import com.baizhi.service.AddressService;
import com.baizhi.service.impl.AddressServiceImpl;
import org.apache.struts2.ServletActionContext;

import java.util.List;

public class AddressAction {
    private List<Address> list;
    private AddressService as=new AddressServiceImpl();
    private String name;
    private String email;
    private String phone;
    private int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String eamil) {
        this.email = eamil;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public List<Address> getList() {
        return list;
    }

    public void setList(List<Address> list) {
        this.list = list;
    }
    public String showAddress(){
        int uid =(int) ServletActionContext.getRequest().getSession().getAttribute("uid");
        list = as.findAddress(uid);
        System.out.println(list);
        return "showAds";
    }
    public String insertAddress(){
        int uid =(int) ServletActionContext.getRequest().getSession().getAttribute("uid");
        System.out.println(email);
        System.out.println(name);
        System.out.println(phone);
        System.out.println(uid);
        boolean b = as.insertAddress(name, email, phone, uid);
        return "insertAddress";
    }
    public String updateState(){
        boolean b = as.updateState();
        if (b){
            boolean selected_state = as.updateState("selected_state", id,1);
        }
        return "update";
    }
    public String updateState1(){
        boolean selected_state = as.updateState("delete_state", id,1);
        System.out.println(id);
        System.out.println(selected_state);
        return "update1";
    }
    public String updateState2(){
        boolean selected_state = as.updateState("delete_state", id,0);
        System.out.println(id);
        System.out.println(selected_state);
        return "update2";
    }
    public String zhanshi(){
        int uid =(int) ServletActionContext.getRequest().getSession().getAttribute("uid");
        list = as.findAddress(uid);
        ServletActionContext.getRequest().getSession().setAttribute("list",list);
        return "zhanshi";
    }
}
